perf(queue): claim the actuation lock before the refresh it exists to prevent - #10181
Merged
Merged
Conversation
… prevent The publish-and-maintain pass refreshed PR details and THEN asked "does another pass already own this PR", so every contended pass did the work and threw it away. github_app.pr_public_surface_lock_contended is the single most frequent audit event on the production Orb: 1,180 occurrences between 09:00 and 10:53 today, roughly 10 per minute and about twice the next event. Each one is a discarded pass. The cost is real but worth stating precisely. refreshPullRequestDetails is itself cached -- it consults the detail-sync state and reuses stored pull_request_files rows when the last sync covered the current head SHA -- so a contention does not always cost a GitHub call. It always costs the sync-state reads, and on a cache miss it costs a token fetch plus the files/reviews fetch. That miss is what a busy PR produces, and a busy PR is also what contends, so the two peak together. This happened in the same window the installation exhausted its REST quota and 66 queue jobs stalled behind deferred_by: rate_limit. Claiming first changes no semantics: the lock's stated purpose (#9013) is to make "does another pass already own this PR" one question with one answer for the whole publish-then-maintain unit, and asking it before the expensive part is strictly better. Holding it across the refresh is already safe -- #9467 renews the lock while work runs precisely because this unit can span an AI review far longer than a refresh. The second contention site is deliberately untouched: it does not refresh beforehand, so it does not have this defect. Guarded by a test asserting SOURCE ORDER, which is unusual and deliberate. Both orderings behave identically on the happy path and differ only in what a LOSING pass spends before it throws, so no behavioural test can distinguish them -- which is why this drifted unnoticed. The test anchors on the publish pass's own contention audit event so an unrelated claim elsewhere in this 16k-line file cannot satisfy it, and asserts both landmarks still exist so a rename cannot make it pass vacuously. Closes #10174
Contributor
|
Important 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏳ LoopOver is waiting…LoopOver has seen this pull request and is waiting on CI checks to finish before reviewing it. This comment will update once the review runs. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟨 Waiting |
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10181 +/- ##
==========================================
- Coverage 92.21% 91.34% -0.88%
==========================================
Files 932 932
Lines 114115 114115
Branches 27566 27566
==========================================
- Hits 105231 104237 -994
- Misses 7583 8772 +1189
+ Partials 1301 1106 -195
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10174
The publish-and-maintain pass refreshed PR details and then asked "does another pass already own this PR?" — so every contended pass did the work and threw it away.
Volume
github_app.pr_public_surface_lock_contendedis the most frequent audit event on the Orb — 1,180 between 09:00 and 10:53 today, ~10/min, about 2× the next event:Cost, stated precisely
refreshPullRequestDetailsis itself cached — it consults the detail-sync state and reuses storedpull_request_filesrows when the last sync covered the current head SHA. So a contention does not always cost a GitHub call, and I am not claiming 1,180 wasted API calls.It always costs the sync-state reads plus
shouldRefreshFilesForPreMergeChecks; on a cache miss it costs a token fetch plus the files/reviews fetch. That miss is what a busy PR produces — and a busy PR is also what contends, so the two peak together. This is the same window in which the installation hitAPI rate limit exceeded for installation ID 143010787and 66 queue jobs stalled behinddeferred_by: rate_limit.Why this is safe
No semantic change. The lock's stated purpose (#9013) is to make "does another pass already own this PR" one question with one answer for the whole publish-then-maintain unit; asking it before the expensive part is strictly better.
Holding it across the refresh is already handled — #9467 renews the lock while work runs, precisely because this unit can span an AI review far longer than a refresh.
The second contention site (~7766) is deliberately untouched: it does not refresh beforehand, so it does not have this defect.
On the test asserting source order
Unusual, and deliberate. Both orderings behave identically on the happy path and differ only in what a losing pass spends before it throws — so no behavioural test can distinguish them. That is exactly why this drifted unnoticed.
Mitigations against the usual failure modes of such a test:
claimPrActuationLockelsewhere in this 16k-line file cannot satisfy it;Verification
Full suite 26,344 passed / 0 failed;
typecheck,dead-exports,dead-source-filesclean.